package com.erpanderp.wam.tm.view;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.AjaxBehaviorEvent;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.swing.SwingWorker;

import org.primefaces.context.RequestContext;
import org.primefaces.model.DefaultStreamedContent;
import org.primefaces.model.StreamedContent;

import com.erpanderp.wam.tm.model.entity.Band;
import com.erpanderp.wam.tm.model.entity.RRFManagerRecommendation;
import com.erpanderp.wam.tm.model.entity.RRFOfferLetterHRInputs;
import com.erpanderp.wam.tm.model.entity.RecruitmentProfile;
import com.erpanderp.wam.tm.model.entity.RecruitmentRequest;
import com.erpanderp.wam.tm.model.service.RRFDAO;
import com.erpanderp.wam.tm.model.service.RRFOfferLetterHRInputsDAO;
import com.erpanderp.wam.tm.model.service.RecruitmentProfileDAO;
import com.erpanderp.wam.usm.model.entity.user.Employee;
import com.erpanderp.wam.usm.model.entity.user.WAMUser;
import com.erpanderp.wam.usm.model.service.user.EmployeeAndReportingDAO;
import com.erpanderp.wam.usm.model.service.user.EmployeeDAO;
import com.erpanderp.wam.util.CommonLookup;
import com.erpanderp.wam.util.EmailUtil;
import com.erpanderp.wam.util.ValidationUtil;
import com.erpanderp.wam.util.WAMHostManager;
import com.erpanderp.wam.util.WAMUtil;

@ManagedBean
@ViewScoped
public class ScheduleInterviewsBean implements Serializable{

	private static final long serialVersionUID = 1L;
	private Map<String,String> interviewModeMap = CommonLookup.getInterviewMode();
	private Map<String,String> releaseOfferLetterMap = CommonLookup.getAuthenticationsMap();
	private TimeZone timeZone = TimeZone.getDefault();
	private ServletContext context = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
	private HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
	private HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
	private WAMUser wamUser = (WAMUser) session.getAttribute(CommonLookup.SESSION_ATTRIBUTE_WAMUSER);
	
    private EmailUtil emailUtil;
    private WAMUtil wamUtil = new WAMUtil();
	private String EMAIL_MESSAGE;
	private StreamedContent file; 
    private String activity;
	private String rrfCode;
	
	private boolean disableInterviewer1Date;
	private boolean disableInterviewer2Date;
	private boolean disableRecruiterDate;
	private boolean hrInputExists;
	private boolean HRINPUT_VALID;
	private boolean renderBackButton; 
	private boolean renderCloseButton; 
	private boolean FORM_VALID;
	
	private RecruitmentRequest recruitmentRequest = new RecruitmentRequest();
	private RecruitmentProfile recruitmentProfile = new RecruitmentProfile();
	private RecruitmentProfile downloadProfile;
	private RRFOfferLetterHRInputs rrfOfferLetterHRInputs=new RRFOfferLetterHRInputs();
	private RRFManagerRecommendation rrfManagerRecommendation =new RRFManagerRecommendation();
	
	private List<RecruitmentProfile> recruitmentProfiles = new ArrayList<RecruitmentProfile>();
	private Map<String, Long> bandsMap = new HashMap<String, Long>();
	private List<Band> bands = new ArrayList<Band>();
	private Map<String, String> hrsMap = new HashMap<String, String>();
	private List<Employee> hrList = new ArrayList<Employee>();
	
	private RecruitmentProfileDAO recruitmentProfileDAO=new RecruitmentProfileDAO();
	private RRFOfferLetterHRInputsDAO rrfOfferLetterHRInputsDAO=new RRFOfferLetterHRInputsDAO();
	private RRFDAO rrfDAO = new RRFDAO();
	private EmployeeDAO employeeDAO = new EmployeeDAO();
	
	private int sno=1;
	private Employee employeeVP;
	private String requestDate;
	private Date dateAfterFourMnths;
	
	public ScheduleInterviewsBean() {
		
		  rrfCode = request.getParameter("rrfCode");
		  activity = request.getParameter("activity");
		  
		  if(activity != null && rrfCode != null){
			  session.setAttribute("rrfCode", rrfCode);
			  session.setAttribute("activity", activity);
		  }else{
			  rrfCode = (String) session.getAttribute("rrfCode");
			  activity = (String) session.getAttribute("activity");
		  }
		  
		  recruitmentRequest = rrfDAO.getRRFByRecruitmentRequestCode(rrfCode);
		  
		  SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy");
		  requestDate = sdf.format(recruitmentRequest.getRequestDate());
		  Calendar currentDate = Calendar.getInstance();
		    //get after four months
			currentDate.add(Calendar.MONTH,4);
			try {
				dateAfterFourMnths = (Date)sdf.parse(sdf.format(currentDate.getTime()));
			} catch (ParseException e) {
				e.printStackTrace();
			} 

		  employeeVP = employeeDAO.getVP();
		  
		  if(wamUser != null){
				renderBackButton=true;
			}else{				
				renderCloseButton=true;
			}
		  
		  hrList=employeeDAO.getAllHrs();
			for (Employee hr : hrList) {
				hrsMap.put(hr.getFirstName()+" "+hr.getLastName(), hr.getFirstName()+" "+hr.getLastName());
			}
		  
		  System.out.println("Activity: " + activity);
		  if(activity.equals("ScheduleByInterviewer1") || activity.equals("ScheduleByInterviewer2")){
			 setDisableRecruiterDate(true);
		  }
		  if(activity.equals("FinalizeScheduleTimes") && recruitmentRequest.getInterviewerFBLevel().equalsIgnoreCase("Level1")){
			 setDisableInterviewer1Date(true);
		  }		
		  if(activity.equals("FinalizeScheduleTimes2") && recruitmentRequest.getInterviewerFBLevel().equalsIgnoreCase("Level2")){
				 setDisableInterviewer2Date(true);
		  }	
		  
		  if(activity.equals("releaseOfferLetter") || activity.equals("OfferLetterApprovedByManager")){
			  recruitmentProfiles = recruitmentProfileDAO.getALLApprovedRRFProfilesByRRFCode(rrfCode);
		  }else{		      
			  recruitmentProfiles = recruitmentProfileDAO.getRecruitmentProfilesByRRFCode(rrfCode);
		  } 
		  
		  for(RecruitmentProfile recruitmentProfile : recruitmentProfiles){
			  recruitmentProfile.setSno(sno);
			  sno++;
		  }
		 
		  if(activity.equals("ScheduleByRecruiter")){
			  for(RecruitmentProfile recruitmentProfile : recruitmentProfiles){
				  recruitmentProfile.setRecruiterScheduleTime(null);
			  }
			  
		  }
		 
		  for(RecruitmentProfile recruitmentProfile : recruitmentProfiles){
			  String interviewer1FBStatus = recruitmentProfile.getInterviewer1FeedbackStatus();
			  String interviewer2FBStatus = recruitmentProfile.getInterviewer2FeedbackStatus();
			  
			 
			  if(recruitmentRequest.getInterviewerFBLevel().equalsIgnoreCase("Level1")){			  
				  if(interviewer1FBStatus.equalsIgnoreCase("Available")){
					  recruitmentProfile.setDisableCreateFeedBack(true);
				  }
			  }
			  if(recruitmentRequest.getInterviewerFBLevel().equalsIgnoreCase("Level2")){			  
				  if(interviewer1FBStatus.equalsIgnoreCase("Available")){
					  recruitmentProfile.setDisableCreateFeedBack(true);
				  }
			  }
			  if(recruitmentRequest.getInterviewerFBLevel().equalsIgnoreCase("Level2-Finished")){			  
				  if(interviewer2FBStatus.equalsIgnoreCase("Available")){
					  recruitmentProfile.setDisableCreateFeedBack(true);
				  }
			  }
		  }
		  bands = rrfDAO.getAllBands();
			for (Band band : bands) {
				bandsMap.put(band.getBand(), band.getBandId());
			}
	}
	
	//CLOSE DIALOG BOX
		public void dialogClose(ActionEvent e){
			//travelRequests.set(travelRequests.indexOf(travelRequest), travelRequestDAO.getTravelRequestById(travelRequest.getTravelRequestId()));
			RequestContext.getCurrentInstance().execute("offerLetterDialog.hide()");		
		}
		
	//FILE DOWNLOAD ACTION
		public void fileDownload(ActionEvent e) throws FileNotFoundException{
			Map<String,String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
			String candidateEmail = params.get("candidateEmail");
			System.out.println("filePath FROM PARAM = "+candidateEmail);
			recruitmentProfile = recruitmentProfileDAO.getRecruitmentProfileByCandidateEmail(candidateEmail);	
			ExternalContext extContext = FacesContext.getCurrentInstance().getExternalContext();        
		    File result = new File(extContext.getRealPath("//RRFResumes//"+recruitmentProfile.getUploadFilePath()));        
		    InputStream stream = new FileInputStream(result.getAbsolutePath());
		    setFile(new DefaultStreamedContent(stream, "application/msword","ERPandERPDBProfile"));		
		}
	 //APPROVE OFFER LETTER BY MANAGER
	 public String apprroveOfferLetterAction() {
		 try{
			  Map<String,String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();

			  String rrfCode = params.get("rrfCode2");
			  String activity=params.get("activity");
			  String candidateEmail=params.get("candidateEmail2");
			  
			  System.out.println("activity::::::::::"+activity);
			  
			  FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("rrfCode", rrfCode);		  
			  FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("activity", activity);
			  FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("candidateEmail", candidateEmail);
			  
			 
				FacesContext.getCurrentInstance().getExternalContext().redirect("/wam/tm/viewofferletter.html?rrfCode="+rrfCode+"&activity="+activity+"&candidateEmail="+candidateEmail);
			  
		  }catch (Exception e) {
			  e.printStackTrace();
		 }
		 return "viewofferletter";
	}
	//Check whether the date is before rrf date or not 
	 public void checkDateListener(AjaxBehaviorEvent e){
		 
		 //<p:ajax event="change" listener="#{scheduleInterviewsBean.checkDateListener}" update="@form"/>   
		// <f:attribute name="recruiterScheduleTime" value="#{profile}" />
		 
		 Date toDate,fromDate;
		 System.out.println("===========checkDateListener============");
		 RecruitmentProfile rrfProfile=null;
		 rrfProfile = (RecruitmentProfile) e.getComponent().getAttributes().get("recruiterScheduleTime");
		
			 toDate = rrfProfile.getRecruiterScheduleTime();
			 fromDate=recruitmentRequest.getRequestDate();
			 System.out.println("===========toDate============"+toDate);
			 System.out.println("===========fromDate============"+fromDate);
		     
			 if(toDate.before(fromDate)){
				   FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_WARN," Please choose date afer recruitment request date", ""));
				   rrfProfile.setRecruiterScheduleTime(null);
				   
			   }
	 }
	
	//SHORT RESOURCES ACTION
		public void scheduleByRecruiterAction(ActionEvent e1) {	
		
		validateForm();
		if(FORM_VALID){
			try{
				 if (recruitmentProfiles.size() > 0 ) {	
					 
					 if(activity.equals("ScheduleByRecruiter")  && recruitmentRequest.getInterviewerFBLevel().equalsIgnoreCase("Level1")){
						 for(RecruitmentProfile rrfProfile : recruitmentProfiles){
							 rrfProfile.setInterviewer1ScheduleTime(rrfProfile.getRecruiterScheduleTime());
							 rrfProfile.setFinalInterviewDates(rrfProfile.getRecruiterScheduleTime());
						 }
					 }
					 
					 if(activity.equals("ScheduleByRecruiter") && recruitmentRequest.getInterviewerFBLevel().equalsIgnoreCase("Level2")){
						 for(RecruitmentProfile rrfProfile : recruitmentProfiles){
							 rrfProfile.setInterviewer2ScheduleTime(rrfProfile.getRecruiterScheduleTime());
							 rrfProfile.setFinalInterviewDates(rrfProfile.getRecruiterScheduleTime());
						 }
					 }
					
					 if(activity.equals("ScheduleByInterviewer1")){						 
						 for(RecruitmentProfile rrfProfile : recruitmentProfiles){
							 if( rrfProfile.getInterviewer1ScheduleTime()!= null ){
								 rrfProfile.setFinalInterviewDates(rrfProfile.getInterviewer1ScheduleTime());
							 }
						 }
					 }
					 
					 if(activity.equals("FinalizeScheduleTimes")){
						 for(RecruitmentProfile rrfProfile : recruitmentProfiles){
							 if( rrfProfile.getRecruiterScheduleTime() != null){
								 rrfProfile.setFinalInterviewDates(rrfProfile.getRecruiterScheduleTime());
							 }
						 }
					 }
					 
					recruitmentProfileDAO.saveRecruitmentProfiles(recruitmentProfiles);
					
					System.out.println("AT CALLER METHOD: " + sendMessage());  //*******DONT REMOVE*******
					
			     }else{
			    	 System.out.println("====There are no profiles in the list====");
			     }
		 
			   if(activity.equals("ScheduleByRecruiter")){
					recruitmentRequest.setRecritmentStatus("SCHEDULED BY RECRUITER");
				    rrfDAO.updateRRFRequest(recruitmentRequest);
				   FacesContext.getCurrentInstance().addMessage("", new FacesMessage(FacesMessage.SEVERITY_INFO, "Interviews scheduled successfully.", ""));
			   }else if(activity.equals("ScheduleByInterviewer1") ){
					recruitmentRequest.setRecritmentStatus("RESCHEDULED BY INTERVIEWER");
				    rrfDAO.updateRRFRequest(recruitmentRequest);
				   FacesContext.getCurrentInstance().addMessage("", new FacesMessage(FacesMessage.SEVERITY_INFO, "Interviewer scheduled interviews successfully.", ""));
			   }else if(activity.equals("FinalizeScheduleTimes")){
					recruitmentRequest.setRecritmentStatus("INTERVIEW SCHEDULE FINALIZED BY RECRUITER");
				    rrfDAO.updateRRFRequest(recruitmentRequest);
				   FacesContext.getCurrentInstance().addMessage("", new FacesMessage(FacesMessage.SEVERITY_INFO, "Interviews scheduled successfully.", ""));
			   }else if(activity.equals("CreateFeedBack")){
				   //recruitmentProfiles
				   
				   
				   FacesContext.getCurrentInstance().addMessage("", new FacesMessage(FacesMessage.SEVERITY_INFO, "Feedbacks are submitted successfully.", ""));
			   }else{
				   FacesContext.getCurrentInstance().addMessage("", new FacesMessage(FacesMessage.SEVERITY_INFO, "You have submitted successfully.", ""));
			   }
			
			}catch (Exception e) {
				e.printStackTrace();
				FacesContext.getCurrentInstance().addMessage("", new FacesMessage(FacesMessage.SEVERITY_ERROR, "Failed to scheduled Interviews.", e.getMessage()));
			}
			
		 }
			
		}
      //CRAETE FEEDBACK
		public String createFeedbackAction() throws IOException {
			System.out.println("================createFeedbackAction===================");
			 
			  Map<String,String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
			  
			  String rrfCode = params.get("rrfCode");	
			  String candidateEmail=params.get("candidateEmail");	
			  
			  FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("rrfCode", rrfCode);
			  FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("candidateEmail", candidateEmail);
			 
			  
			  FacesContext.getCurrentInstance().getExternalContext().redirect("/wam/tm/createfeedback.html?rrfCode="+rrfCode+"&candidateEmail="+candidateEmail);
			  
			  System.out.println("rrfCode ==" + FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get("rrfCode"));
			  System.out.println("candidateEmail ==" + FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get("candidateEmail"));
			 
			  
			  return "createfeedback";
		 
	  }
	
    //VIEW FEEDBACK
	public String viewFeedbackAction(ActionEvent ae) throws IOException {
		
		  System.out.println("================viewFeedbackAction===================");
		
		  Map<String,String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
		  
		  String rrfCode = params.get("rrfCode1");	
		  String candidateEmail=params.get("candidateEmail1");	
		 
		  FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("rrfCode", rrfCode);
		  FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("candidateEmail", candidateEmail);
		  FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("activity", activity);
		 		  
		  FacesContext.getCurrentInstance().getExternalContext().redirect("/wam/tm/viewfeedback.html?rrfCode="+rrfCode+"&candidateEmail="+candidateEmail+"&activity="+activity);
		  
		  return "viewfeedback";
			 
	 }
	//GENERATE OFFER LETTER ACTION
	 String rrfCode2;
	 String candidateEmail2;
	public void generateOfferLetterListener(ActionEvent e)  {
			 
			 Map<String,String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
			  
			  rrfCode2 = params.get("rrfCode2");	
			  candidateEmail2=params.get("candidateEmail2");
	
			  recruitmentProfile=recruitmentProfileDAO.getRecruitmentProfileByCandidateEmail(candidateEmail2);
			  
			  rrfManagerRecommendation = recruitmentProfileDAO.getRRFManagerRecommendationByProfileId(recruitmentProfile.getRecruitmentProfileId(),recruitmentProfile.getRecruitmentRequestCode());
	
			  rrfOfferLetterHRInputs.setEmployeeGrossSalary(rrfManagerRecommendation.getErpOfferPriceLPA().toString());
			   int number =Integer.parseInt(rrfOfferLetterHRInputs.getEmployeeGrossSalary());
			   System.out.println("====222222222222================="+number);
			   String numberToWords = wamUtil.NumberToWords(number);
			   System.out.println("====3333333333333================="+numberToWords);
			   rrfOfferLetterHRInputs.setGrossSalaryInWords(numberToWords);
			   rrfOfferLetterHRInputs.setEmployeeDateOfJoining(recruitmentProfile.getExpectedJoiningDate());
			   rrfOfferLetterHRInputs.setGenearatedOfferLetterDate(new Date());
			  
			  hrInputExists=rrfOfferLetterHRInputsDAO.isHRInputExistOrNot(rrfCode2, recruitmentProfile.getRecruitmentProfileId());
						 
			  if(hrInputExists){	
				  rrfOfferLetterHRInputs = rrfOfferLetterHRInputsDAO.getRRFOfferLetterHRInputsByProfileId(rrfCode2, recruitmentProfile.getRecruitmentProfileId());		  
			  }else{
				  System.out.println("DOESN't EXIST...");
			  }
	 }
	 public void createOfferLetterListener(ActionEvent e)  {
			
	   hrInputsValidateForm();
	   if(HRINPUT_VALID){
		 
		  recruitmentProfile=recruitmentProfileDAO.getRecruitmentProfileByCandidateEmail(candidateEmail2);
		  recruitmentRequest = rrfDAO.getRRFByRecruitmentRequestCode(rrfCode2);
		  
		  //String addWithCommas = wamUtil.addCommasToNumber(rrfOfferLetterHRInputs.getEmployeeGrossSalary());
		  //rrfOfferLetterHRInputs.setEmployeeGrossSalary(addWithCommas);
		  rrfOfferLetterHRInputs.setEmployeeGrossSalary(rrfOfferLetterHRInputs.getEmployeeGrossSalary());
					 
		  rrfOfferLetterHRInputs.setRecruitmentRequestCode(rrfCode2);
		  rrfOfferLetterHRInputs.setRecruitmentProfileId(recruitmentProfile);
		  rrfOfferLetterHRInputs.setRecruitmentRequestId(recruitmentRequest);
		  rrfOfferLetterHRInputs.setGenearatedOfferLetterDate(new Date());
		  rrfOfferLetterHRInputs.setEmployeePosition(recruitmentProfile.getBand().getBusinessFunction());
		  rrfOfferLetterHRInputs.setBand(recruitmentProfile.getBand().getBand());
		  rrfOfferLetterHRInputs.setCreateDate(new Date());
		  rrfOfferLetterHRInputs.setCreatedBy(CommonLookup.CREATEDBY_DEVELOPER_TEXT);
		  rrfOfferLetterHRInputs.setStatus(CommonLookup.STATUS_ACTIVE);
		  rrfOfferLetterHRInputsDAO.saveRRFOfferLetterHRInputs(rrfOfferLetterHRInputs);
		  rrfOfferLetterHRInputs = new RRFOfferLetterHRInputs();
		  
		  
		  System.out.println("BEFDORE SET VALUES TO FACESCONTEXT:::::::::::::::");
		  FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("rrfCode", rrfCode2);
		  FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("candidateEmail", candidateEmail2);
		 
		 		  
			try {
				FacesContext.getCurrentInstance().getExternalContext().redirect("/wam/tm/viewofferletter.html?rrfCode="+rrfCode2+"&candidateEmail="+candidateEmail2+"&activity=OfferLetterGoesToApproval");
			}catch (IOException e1) {
				System.out.println("EXCEPTION PAGE RENDERING:::::::::::::::::::::::");
				e1.printStackTrace();
			}
	    }else{
	    	//offerLetterDialog.
	    	RequestContext.getCurrentInstance().execute("offerLetterDialog.show();");
	    }
	 }
	 
	//Final validation 
	private void validateForm(){
		FORM_VALID=true;
		
		int count = recruitmentProfiles.size();
		
		System.out.println("=========count============="+count);
		
		
		for(RecruitmentProfile recruitmentProfile : recruitmentProfiles){
			
			Date recruiterSchedule = recruitmentProfile.getRecruiterScheduleTime() ;
			if(recruiterSchedule == null){
				FORM_VALID = false ;
			}else{
				FORM_VALID = true ;
				break;
			}
		}
		
		if(!FORM_VALID){
			FORM_VALID = false;
			 FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_WARN,"Please select schedule date and time.", ""));
		}
		
	}
	 
	// HR INPUTS VALIDATIONS
	private void hrInputsValidateForm() {
		HRINPUT_VALID = true;

		if (ValidationUtil.isEmpty(rrfOfferLetterHRInputs.getHrReferenceNo(), " HR Reference Number", null,
				FacesContext.getCurrentInstance()) != null) {
			HRINPUT_VALID = false;
		}
		if (ValidationUtil.isEmpty(rrfOfferLetterHRInputs.getEmployeeGrossSalary(), "Employee Gross Salary",
				null, FacesContext.getCurrentInstance()) != null) {
			HRINPUT_VALID = false;
		}
		if (ValidationUtil.isEmpty((rrfOfferLetterHRInputs.getEmployeeDateOfJoining()!=null) ? rrfOfferLetterHRInputs.getEmployeeDateOfJoining().toString():null, "Employee Date of Joining", null,
				FacesContext.getCurrentInstance()) != null) {
			HRINPUT_VALID = false;
		}else{
			if(rrfOfferLetterHRInputs.getEmployeeDateOfJoining().before(recruitmentRequest.getRequestDate())){
			 FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN,  "Employee Date of Joining should be grater than RRF raise date("+requestDate+").", ""));
			 HRINPUT_VALID = false;
			}
			if(rrfOfferLetterHRInputs.getEmployeeDateOfJoining().after(dateAfterFourMnths)){
				 HRINPUT_VALID = false;
				   FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_WARN,"Employee Date of Joining should not be exceed 4 months from RRF raise date("+requestDate+").", ""));
			   }
		}
		if (ValidationUtil.isEmpty(rrfOfferLetterHRInputs.getHrSignatureName(), "HR Signature Name", null,
				FacesContext.getCurrentInstance()) != null) {
			HRINPUT_VALID = false;
		}
		if (ValidationUtil.isEmpty(rrfOfferLetterHRInputs.getApproverSignatureName(), "Higher Authority Signature Name", null,
				FacesContext.getCurrentInstance()) != null) {
			HRINPUT_VALID = false;
		}
		if (ValidationUtil.isEmpty(rrfOfferLetterHRInputs.getApproverSignaturePosition(), "Higher Authority Signature Position", null,
				FacesContext.getCurrentInstance()) != null) {
			HRINPUT_VALID = false;
		}		
	}
		//Conver Number to words
		public void covertNumberToWord(AjaxBehaviorEvent e)  {
			System.out.println("INSIDE CHANGE ACTION ===========SALAERY====="+rrfOfferLetterHRInputs.getEmployeeGrossSalary());
			 int number =Integer.parseInt(rrfOfferLetterHRInputs.getEmployeeGrossSalary());
			 String numberToWords = wamUtil.NumberToWords(number); 
			 System.out.println("numberToWords==========="+numberToWords);
			 rrfOfferLetterHRInputs.setGrossSalaryInWords(numberToWords);
		}
		//SENDING EMAIL 
		public String sendMessage(){
			Map<String, String> hostsMap = WAMHostManager.getWAMHosts(context);
			String domainName = context.getInitParameter("domainName");
			String messageString ="";
			EmployeeAndReportingDAO employeeAndReportingDAO = new EmployeeAndReportingDAO();
			Employee vp = employeeAndReportingDAO.getEmployeeByDesignation(CommonLookup.DESIGNATION_VICE_PRESIDENT_VALUE);
			Employee hr = employeeAndReportingDAO.getEmployeeByDesignation(CommonLookup.DESIGNATION_SENIOR_HR_VALUE);
			
			String interviewer1Email =null;
			String interviewer2Email =null;
			String managerEmail = null;
			String recruiterEmail = null;
			String vpEmail = vp == null ? "" : vp.getEmail();
			String hrEmail = hr == null ? "" : hr.getEmail();;
			
			emailUtil = new EmailUtil();
			if (hostsMap.get(CommonLookup.DEV_EMAIL) == null) {
				System.out.println("PRODUCTION");
				interviewer1Email = recruitmentRequest.getInterviewer1().getEmail();
				interviewer2Email = recruitmentRequest.getInterviewer2().getEmail();;
				managerEmail = recruitmentRequest.getEmployee().getEmail();
				recruiterEmail =recruitmentRequest.getRecruiter().getEmail();
				vpEmail = vp == null ? "" : vp.getEmail();
				hrEmail = hr == null ? "" : hr.getEmail();
			} else {
				System.out.println("DEVELOPMENT");
				interviewer1Email = hostsMap.get(CommonLookup.DEV_EMAIL);
				interviewer2Email = hostsMap.get(CommonLookup.DEV_EMAIL);
				managerEmail = hostsMap.get(CommonLookup.DEV_EMAIL);
				recruiterEmail =hostsMap.get(CommonLookup.DEV_EMAIL);
				vpEmail = hostsMap.get(CommonLookup.DEV_EMAIL);
				hrEmail = hostsMap.get(CommonLookup.DEV_EMAIL);				
			}
			
			
		   if(activity.equalsIgnoreCase("ScheduleByRecruiter")){ 			   
				
				if(recruitmentRequest.getInterviewerFBLevel().equalsIgnoreCase("Level1")){
				System.out.println("Level1========ScheduleByRecruiter========");
				String[] to={interviewer1Email};
				String[] cc={managerEmail};
					
				String requestURL = "tm/scheduleinterviews.html?rrfCode=" + rrfCode+"&activity=ScheduleByInterviewer1";
				String privateLink = "http://" + hostsMap.get(CommonLookup.PRIVATEHOST) + "/" + domainName + "/" + requestURL;
				String publicLink = "http://" + hostsMap.get(CommonLookup.PUBLICHOST) + "/"	+ domainName + "/" + requestURL;
				
				messageString = "Dear " + recruitmentRequest.getInterviewer1().getFirstName() + " " + recruitmentRequest.getInterviewer1().getLastName() + "" +
								",<br/><br/>" +									
					"<table style='border: 1px solid #d9d9d9;'>" +
			        "<tr> <td>Recruitment Request Code </td><td> : </td><td>" + rrfCode+ " </td></tr>" +
			        "<tr> <td>Technology</td><td> : </td> <td>" + recruitmentRequest.getTechnology().getDisplayName() + " </td></tr>" +						       
			        "</table><br/>"+	
			        "<b>Please provide your available time for interview schedule</b><br/><br/>"+
			        "<a style='color:#FF9933;font-weight: bold;' href=\""+
			        privateLink + "\">" + "Please click here to schedule your available time" + "</a /><br />"+
					"(Employees who are in Hyderabad office)"+"<br /><br />"+
					"<a style='color:#FF9933;font-weight: bold;' href=\""+
					publicLink + "\">" + "Please click here to schedule your available time" + "</a /><br />"+
					"(out side Hyderabad office)"+"<br /><br />"+
					
					"Thanks & Regards, <br />"+CommonLookup.WAM_DEVTEAM_SIGNATURE;
				
				emailUtil = new EmailUtil();
				emailUtil.setMessage(messageString);
				emailUtil.setRecieverAddresses(to);
				emailUtil.setCCAddresses(cc);
				emailUtil.setSenderEmail("podquick@erpanderp.com", "WAM - Dev Team");
				
				emailUtil.setSubject("RRF Request (" + rrfCode + ")- Schedule interviewer available time");
				
				}
				
				if(recruitmentRequest.getInterviewerFBLevel().equalsIgnoreCase("Level2")){
					System.out.println("Level2========ScheduleByRecruiter========");
					String[] to={interviewer2Email};//2nd int
					String[] cc={managerEmail};
						
					String requestURL = "tm/scheduleinterviews.html?rrfCode=" + rrfCode+"&activity=ScheduleByInterviewer2";
					String privateLink = "http://" + hostsMap.get(CommonLookup.PRIVATEHOST) + "/" + domainName + "/" + requestURL;
					String publicLink = "http://" + hostsMap.get(CommonLookup.PUBLICHOST) + "/"	+ domainName + "/" + requestURL;
					
					messageString = "Dear " + recruitmentRequest.getInterviewer2().getFirstName() + " " + recruitmentRequest.getInterviewer2().getLastName() + "" +
									",<br/><br/>" +									
						"<table style='border: 1px solid #d9d9d9;'>" +
				        "<tr> <td>Recruitment Request Code</td><td> : </td><td>" + rrfCode+ " </td></tr>" +
				        "<tr> <td>Technology</td><td> : </td> <td>" + recruitmentRequest.getTechnology().getDisplayName() + " </td></tr>" +						       
				        "</table><br/>"+	
				        "<b>Please click here to schedule your available time for second level</b><br/><br/>"+
				        "<a style='color:#FF9933;font-weight: bold;' href=\""+
				        privateLink + "\">" + "Please click here to schedule your available time" + "</a /><br />"+
						"(Employees who are in Hyderabad office)"+"<br /><br />"+
						"<a style='color:#FF9933;font-weight: bold;' href=\""+
						publicLink + "\">" + "Please click here to schedule your available time" + "</a /><br />"+
						"(out side Hyderabad office)"+"<br /><br />"+
						
						"Thanks & Regards, <br />"+CommonLookup.WAM_DEVTEAM_SIGNATURE;
					
					emailUtil = new EmailUtil();
					emailUtil.setMessage(messageString);
					emailUtil.setRecieverAddresses(to);
					emailUtil.setCCAddresses(cc);
					emailUtil.setSenderEmail("podquick@erpanderp.com", "WAM - Dev Team");
					
					emailUtil.setSubject("RRF Request (" + rrfCode + ")- Schedule Your Available Time For Second level Interview");
				}
			}
		   //=====================================================================================================
			if(activity.equalsIgnoreCase("ScheduleByInterviewer1") || activity.equalsIgnoreCase("ScheduleByInterviewer2")){ 
				System.out.println("INTERVIEWER 1========ScheduleByInterviewer1======================");
				
				if(recruitmentRequest.getInterviewerFBLevel().equalsIgnoreCase("Level1")){
					System.out.println("Level1 1========ScheduleByInterviewer1======================");
					String[] to={recruiterEmail};
					String[] cc={managerEmail};
					
					String requestURL = "tm/scheduleinterviews.html?rrfCode=" + rrfCode+"&activity=FinalizeScheduleTimes";
					String privateLink = "http://" + hostsMap.get(CommonLookup.PRIVATEHOST) + "/" + domainName + "/" + requestURL;
					String publicLink = "http://" + hostsMap.get(CommonLookup.PUBLICHOST) + "/"	+ domainName + "/" + requestURL;
					
					messageString = "Dear " + recruitmentRequest.getRecruiter().getFirstName() + " " + recruitmentRequest.getRecruiter().getLastName() + "" +
											",<br /><br />" +
											
											"<table style='border: 1px solid #d9d9d9;'>" +
									        "<tr> <td>Recruitment Request Code </td><td> : </td><td>" + rrfCode+ " </td></tr>" +
									        "<tr> <td>Technology</td><td> : </td> <td>" + recruitmentRequest.getTechnology().getDisplayName() + " </td></tr>" +						       
									        "</table><br/>"+	
									        "<b>Please check with the candidates , and re-schedule if any changes </b><br/><br/>"+
									        "<a style='color:#FF9933;font-weight: bold;' href=\""+
									        privateLink + "\">" + "Please click here to know the interviewer schedule times" + "</a /><br />"+
											"(Employees who are in Hyderabad office)"+"<br /><br />"+
											"<a style='color:#FF9933;font-weight: bold;' href=\""+
											publicLink + "\">" + "Please click here to know the interviewer schedule times" + "</a /><br />"+
											"(out side Hyderabad office)"+"<br /><br />"+
											
											"Thanks & Regards, <br />"+CommonLookup.WAM_DEVTEAM_SIGNATURE;;	
					emailUtil = new EmailUtil();
					emailUtil.setMessage(messageString);
					emailUtil.setRecieverAddresses(to);
					emailUtil.setCCAddresses(cc);
					emailUtil.setSenderEmail("podquick@erpanderp.com", "WAM - Dev Team");
	
					emailUtil.setSubject("RRF Request (" + rrfCode + ")- Interviewer scheduled times for interviews");
				}
				if(recruitmentRequest.getInterviewerFBLevel().equalsIgnoreCase("Level2")){
					System.out.println("Level2========ScheduleByInterviewer2======================");
					String[] to={recruiterEmail};
					String[] cc={managerEmail};
					
					String requestURL = "tm/scheduleinterviews.html?rrfCode=" + rrfCode+"&activity=FinalizeScheduleTimes2";
					String privateLink = "http://" + hostsMap.get(CommonLookup.PRIVATEHOST) + "/" + domainName + "/" + requestURL;
					String publicLink = "http://" + hostsMap.get(CommonLookup.PUBLICHOST) + "/"	+ domainName + "/" + requestURL;
					
					messageString = "Dear " + recruitmentRequest.getRecruiter().getFirstName() + " " + recruitmentRequest.getRecruiter().getLastName() + "" +
											",<br /><br />" +
											
											"<table style='border: 1px solid #d9d9d9;'>" +
									        "<tr> <td>Recruitment Request Code </td><td> : </td><td>" + rrfCode+ " </td></tr>" +
									        "<tr> <td>Technology</td><td> : </td> <td>" + recruitmentRequest.getTechnology().getDisplayName() + " </td></tr>" +						       
									        "</table><br/>"+	
									        "<b>Please check with the candidates , and re-schedule if any changes for second level  </b><br/><br/>"+
									        "<a style='color:#FF9933;font-weight: bold;' href=\""+
									        privateLink + "\">" + "Please click here to know the interviewer schedule times" + "</a /><br />"+
											"(Employees who are in Hyderabad office)"+"<br /><br />"+
											"<a style='color:#FF9933;font-weight: bold;' href=\""+
											publicLink + "\">" + "Please click here to know the interviewer schedule times" + "</a /><br />"+
											"(out side Hyderabad office)"+"<br /><br />"+
											
											"Thanks & Regards, <br />"+CommonLookup.WAM_DEVTEAM_SIGNATURE;;	
					emailUtil = new EmailUtil();
					emailUtil.setMessage(messageString);
					emailUtil.setRecieverAddresses(to);
					emailUtil.setCCAddresses(cc);
					emailUtil.setSenderEmail("podquick@erpanderp.com", "WAM - Dev Team");

					emailUtil.setSubject("RRF Request (" + rrfCode + ")- Interviewer scheduled times for second level interviews");
					
				}
			
			}
			//================================================================================================
			if(activity.equalsIgnoreCase("FinalizeScheduleTimes") || activity.equalsIgnoreCase("FinalizeScheduleTimes2")){ //Two Loops Not Required
				
				
				if(recruitmentRequest.getInterviewerFBLevel().equalsIgnoreCase("Level1")){
					System.out.println("Level1===============FinalizeScheduleTimes===============");
				String[] to={recruiterEmail};
				String[] cc={managerEmail};
				
				String requestURL = "tm/scheduleinterviews.html?rrfCode=" + rrfCode+"&activity=CreateFeedBack";
				String privateLink = "http://" + hostsMap.get(CommonLookup.PRIVATEHOST) + "/" + domainName + "/" + requestURL;
				String publicLink = "http://" + hostsMap.get(CommonLookup.PUBLICHOST) + "/"	+ domainName + "/" + requestURL;
				
				messageString = "Dear " + recruitmentRequest.getInterviewer1().getFirstName() + " " + recruitmentRequest.getInterviewer1().getLastName() + "" +
										",<br /><br />" +
										
										"<table style='border: 1px solid #d9d9d9;'>" +
								        "<tr> <td>Recruitment Request Code </td><td> : </td><td>" + rrfCode+ " </td></tr>" +
								        "<tr> <td>Technology</td><td> : </td> <td>" + recruitmentRequest.getTechnology().getDisplayName() + " </td></tr>" +						       
								        "</table><br/>"+	
								        "<b>Please evaluate the candidates , and provide your feedback </b><br/><br/>"+
								        "<a style='color:#FF9933;font-weight: bold;' href=\""+
								        privateLink + "\">" + "Please click here to know the schedule times and for createing feedback" + "</a /><br />"+
										"(Employees who are in Hyderabad office)"+"<br /><br />"+
										"<a style='color:#FF9933;font-weight: bold;' href=\""+
										publicLink + "\">" + "Please click here to know the schedule times and for createing feedback" + "</a /><br />"+
										"(out side Hyderabad office)"+"<br /><br />"+
										
										"Thanks & Regards, <br />"+CommonLookup.WAM_DEVTEAM_SIGNATURE;;	
				emailUtil = new EmailUtil();
				emailUtil.setMessage(messageString);
				emailUtil.setRecieverAddresses(to);
				emailUtil.setCCAddresses(cc);
				emailUtil.setSenderEmail("podquick@erpanderp.com", "WAM - Dev Team");

				emailUtil.setSubject("RRF Request (" + rrfCode + ")- Conducting interviews for scheduled candidates");
				}
				if(recruitmentRequest.getInterviewerFBLevel().equalsIgnoreCase("Level2")){
					
					 recruitmentRequest.setInterviewerFBLevel("Level2-Finished");
					 rrfDAO.updateRRFRequest(recruitmentRequest);
					
					System.out.println("Level2===============FinalizeScheduleTimes222222===============");
					String[] to={recruiterEmail};
					String[] cc={managerEmail};
					
					String requestURL = "tm/scheduleinterviews.html?rrfCode=" + rrfCode+"&activity=CreateFeedBack";
					String privateLink = "http://" + hostsMap.get(CommonLookup.PRIVATEHOST) + "/" + domainName + "/" + requestURL;
					String publicLink = "http://" + hostsMap.get(CommonLookup.PUBLICHOST) + "/"	+ domainName + "/" + requestURL;
					
					messageString = "Dear " + recruitmentRequest.getInterviewer2().getFirstName() + " " + recruitmentRequest.getInterviewer2().getLastName() + "" +
											",<br /><br />" +
											
											"<table style='border: 1px solid #d9d9d9;'>" +
									        "<tr> <td>Recruitment Request Code </td><td> : </td><td>" + rrfCode+ " </td></tr>" +
									        "<tr> <td>Technology</td><td> : </td> <td>" + recruitmentRequest.getTechnology().getDisplayName() + " </td></tr>" +						       
									        "</table><br/>"+	
									        "<b>Please evaluate the candidates , and provide your feedback </b><br/><br/>"+
									        "<a style='color:#FF9933;font-weight: bold;' href=\""+
									        privateLink + "\">" + "Please click here to know the schedule times and for createing feedback" + "</a /><br />"+
											"(Employees who are in Hyderabad office)"+"<br /><br />"+
											"<a style='color:#FF9933;font-weight: bold;' href=\""+
											publicLink + "\">" + "Please click here to know the schedule times and for createing feedback" + "</a /><br />"+
											"(out side Hyderabad office)"+"<br /><br />"+
											
											"Thanks & Regards, <br />"+CommonLookup.WAM_DEVTEAM_SIGNATURE;;	
					emailUtil = new EmailUtil();
					emailUtil.setMessage(messageString);
					emailUtil.setRecieverAddresses(to);
					emailUtil.setCCAddresses(cc);
					emailUtil.setSenderEmail("podquick@erpanderp.com", "WAM - Dev Team");

					emailUtil.setSubject("RRF Request (" + rrfCode + ")- Conducting interviews for second level schedule times");
				}
			
			}
			
			//===================================================================================
			
			if(activity.equalsIgnoreCase("CreateFeedBack")){
			
				String[] cc={recruiterEmail};
				String[] to={managerEmail};
		        
				if(recruitmentRequest.getInterviewerFBLevel().equalsIgnoreCase("Level1") || recruitmentRequest.getInterviewerFBLevel().equalsIgnoreCase("Level2-Finished") ){
					System.out.println("============INTerview Level is Single Level");
					
					String requestURL = "tm/scheduleinterviews.html?rrfCode=" + rrfCode+"&activity=CreateManagerRecommendations";
					String privateLink = "http://" + hostsMap.get(CommonLookup.PRIVATEHOST) + "/" + domainName + "/" + requestURL;
					String publicLink = "http://" + hostsMap.get(CommonLookup.PUBLICHOST) + "/"	+ domainName + "/" + requestURL;
					
					messageString = "Dear " + recruitmentRequest.getEmployee().getFirstName() + " " + recruitmentRequest.getEmployee().getLastName() + "" +
											",<br /><br />" +
											
											"<table style='border: 1px solid #d9d9d9;'>" +
									        "<tr> <td>Recruitment Request Code </td><td> : </td><td>" + rrfCode+ " </td></tr>" +
									        "<tr> <td>Technology</td><td> : </td> <td>" + recruitmentRequest.getTechnology().getDisplayName() + " </td></tr>" +						       
									        "</table><br/>"+	
									        "<b>Feedback(s) of evaluated candidates </b><br/><br/>"+
									        "<a style='color:#FF9933;font-weight: bold;' href=\""+
									        privateLink + "\">" + "Please click here to view interview ratings and provide manager recommendations" + "</a /><br />"+
											"(Employees who are in Hyderabad office)"+"<br /><br />"+
											"<a style='color:#FF9933;font-weight: bold;' href=\""+
											publicLink + "\">" + "Please click here to view interview ratings and provide manager recommendations" + "</a /><br />"+
											"(out side Hyderabad office)"+"<br /><br />"+
											
											"Thanks & Regards, <br />"+CommonLookup.WAM_DEVTEAM_SIGNATURE;;	
					emailUtil = new EmailUtil();
					emailUtil.setMessage(messageString);
					emailUtil.setRecieverAddresses(to);
					emailUtil.setCCAddresses(cc);
					emailUtil.setSenderEmail("podquick@erpanderp.com", "WAM - Dev Team");

					emailUtil.setSubject("RRF Request (" + rrfCode + ")- Feedback ratings ");
				}
				
				if(recruitmentRequest.getInterviewerFBLevel().equalsIgnoreCase("Level2")){
					
					System.out.println("============INTerview Level2222222 is Two Level");
					
					String requestURL = "tm/scheduleinterviews.html?rrfCode=" + rrfCode+"&activity=ScheduleByRecruiter";
					String privateLink = "http://" + hostsMap.get(CommonLookup.PRIVATEHOST) + "/" + domainName + "/" + requestURL;
					String publicLink = "http://" + hostsMap.get(CommonLookup.PUBLICHOST) + "/"	+ domainName + "/" + requestURL;
					
					messageString = "Dear " + recruitmentRequest.getRecruiter().getFirstName() + " " + recruitmentRequest.getRecruiter().getLastName() + "" +
											",<br /><br />" +
											
											"<table style='border: 1px solid #d9d9d9;'>" +
									        "<tr> <td>Recruitment Request Code </td><td> : </td><td>" + rrfCode+ " </td></tr>" +
									        "<tr> <td>Technology</td><td> : </td> <td>" + recruitmentRequest.getTechnology().getDisplayName() + " </td></tr>" +						       
									        "</table><br/>"+	
									        "<b>First level interview got over..Please check with candidates and schedule second level interview times  </b><br/><br/>"+
									        "<a style='color:#FF9933;font-weight: bold;' href=\""+
									        privateLink + "\">" + "Please click here to schedule interviews for second level" + "</a /><br />"+
											"(Employees who are in Hyderabad office)"+"<br /><br />"+
											"<a style='color:#FF9933;font-weight: bold;' href=\""+
											publicLink + "\">" + "Please click here to schedule interviews for second level" + "</a /><br />"+
											"(out side Hyderabad office)"+"<br /><br />"+
											
											"Thanks & Regards, <br />"+CommonLookup.WAM_DEVTEAM_SIGNATURE;;	
											
					emailUtil = new EmailUtil();
					emailUtil.setMessage(messageString);
					emailUtil.setRecieverAddresses(to);
					emailUtil.setCCAddresses(cc);
					emailUtil.setSenderEmail("podquick@erpanderp.com", "WAM - Dev Team");

					emailUtil.setSubject("RRF Request (" + rrfCode + ")- Schedule candidate availability for second level ");
				}	
				
			}
          if(activity.equals("CreateManagerRecommendations")){
				
				String[] to={vpEmail}; 
				//String[] cc={recruiterEmail};
				
				String requestURL = "tm/scheduleinterviews.html?rrfCode=" + rrfCode+"&activity=approvedByHigherAuthority";
				String privateLink = "http://" + hostsMap.get(CommonLookup.PRIVATEHOST) + "/" + domainName + "/" + requestURL;
				String publicLink = "http://" + hostsMap.get(CommonLookup.PUBLICHOST) + "/"	+ domainName + "/" + requestURL;
				
				messageString = "Dear " + employeeVP.getFirstName() + " " + employeeVP.getLastName() + "" +
										",<br /><br />" +
										
										"<table style='border: 1px solid #d9d9d9;'>" +
								        "<tr> <td>Recruitment Request Code </td><td> : </td><td>" + rrfCode+ " </td></tr>" +
								        "<tr> <td>Technology</td><td> : </td> <td>" + recruitmentRequest.getTechnology().getDisplayName() + " </td></tr>" +						       
								        "</table><br/>"+	
								        "<b>Selected candidates for your consent</b><br/><br/>"+
								        "<a style='color:#FF9933;font-weight: bold;' href=\""+
								        privateLink + "\">" + "Please click here to Approve/Reject candidates" + "</a /><br />"+
										"(Employees who are in Hyderabad office)"+"<br /><br />"+
										"<a style='color:#FF9933;font-weight: bold;' href=\""+
										publicLink + "\">" + "Please click here to Approve/Reject candidates" + "</a /><br />"+
										"(out side Hyderabad office)"+"<br /><br />"+
										
										"Thanks & Regards, <br />"+CommonLookup.WAM_DEVTEAM_SIGNATURE;;	
				emailUtil = new EmailUtil();
				emailUtil.setMessage(messageString);
				emailUtil.setRecieverAddresses(to);
				//emailUtil.setCCAddresses(cc);
				emailUtil.setSenderEmail("podquick@erpanderp.com", "WAM - Dev Team");

				emailUtil.setSubject("RRF Request (" + rrfCode + ")- Recruitment form approval request");
			
			}if(activity.equals("approvedByHigherAuthority")){
				
				String[] to={managerEmail}; 
				String[] cc={recruiterEmail};
				
				String requestURL = "tm/scheduleinterviews.html?rrfCode=" + rrfCode+"&activity=approvealRecommendation";
				String privateLink = "http://" + hostsMap.get(CommonLookup.PRIVATEHOST) + "/" + domainName + "/" + requestURL;
				String publicLink = "http://" + hostsMap.get(CommonLookup.PUBLICHOST) + "/"	+ domainName + "/" + requestURL;
				
				messageString = "Dear " + recruitmentRequest.getEmployee().getFirstName() + " " + recruitmentRequest.getEmployee().getLastName() + "" +
										",<br /><br />" +
										
										"<table style='border: 1px solid #d9d9d9;'>" +
								        "<tr> <td>Recruitment Request Code </td><td> : </td><td>" + rrfCode+ " </td></tr>" +
								        "<tr> <td>Technology</td><td> : </td> <td>" + recruitmentRequest.getTechnology().getDisplayName() + " </td></tr>" +						       
								        "</table><br/>"+	
								        "<b>Approval recommendation to hire the candidates.</b><br/><br/>"+
								        "<a style='color:#FF9933;font-weight: bold;' href=\""+
								        privateLink + "\">" + "Please click here to view approver recommendations" + "</a /><br />"+
										"(Employees who are in Hyderabad office)"+"<br /><br />"+
										"<a style='color:#FF9933;font-weight: bold;' href=\""+
										publicLink + "\">" + "Please click here to view approver recommendations" + "</a /><br />"+
										"(out side Hyderabad office)"+"<br /><br />"+
										
										"Thanks & Regards, <br />"+CommonLookup.WAM_DEVTEAM_SIGNATURE;;	
				emailUtil = new EmailUtil();
				emailUtil.setMessage(messageString);
				emailUtil.setRecieverAddresses(to);
				emailUtil.setCCAddresses(cc);
				emailUtil.setSenderEmail("podquick@erpanderp.com", "WAM - Dev Team");

				emailUtil.setSubject("RRF Request (" + rrfCode + ")-Hiring Approve/Reject Status");
			
			}
			if(activity.equals("approvealRecommendation")){
				
				String[] to={hrEmail}; 
				String[] cc={recruiterEmail};
				
				String requestURL = "tm/scheduleinterviews.html?rrfCode=" + rrfCode+"&activity=releaseOfferLetter";
				String privateLink = "http://" + hostsMap.get(CommonLookup.PRIVATEHOST) + "/" + domainName + "/" + requestURL;
				String publicLink = "http://" + hostsMap.get(CommonLookup.PUBLICHOST) + "/"	+ domainName + "/" + requestURL;
				
				messageString = "Dear HR" + 
										",<br /><br />" +
										
										"<table style='border: 1px solid #d9d9d9;'>" +
								        "<tr> <td>Recruitment Request Code </td><td> : </td><td>" + rrfCode+ " </td></tr>" +
								        "<tr> <td>Technology</td><td> : </td> <td>" + recruitmentRequest.getTechnology().getDisplayName() + " </td></tr>" +						       
								        "</table><br/>"+	
								        "<b>Please go head to release offer letter.</b><br/><br/>"+
								        "<a style='color:#FF9933;font-weight: bold;' href=\""+
								        privateLink + "\">" + "Please click here to release offer letter to candidates" + "</a /><br />"+
										"(Employees who are in Hyderabad office)"+"<br /><br />"+
										"<a style='color:#FF9933;font-weight: bold;' href=\""+
										publicLink + "\">" + "Please click here to release offer letter to candidates" + "</a /><br />"+
										"(out side Hyderabad office)"+"<br /><br />"+
										
										"Thanks & Regards, <br />"+CommonLookup.WAM_DEVTEAM_SIGNATURE;;	
				emailUtil = new EmailUtil();
				emailUtil.setMessage(messageString);
				emailUtil.setRecieverAddresses(to);
				emailUtil.setCCAddresses(cc);
				emailUtil.setSenderEmail("podquick@erpanderp.com", "WAM - Dev Team");

				emailUtil.setSubject("Release Offer Letter For (" + rrfCode + ")- Recruitment Request Candidates");
			
			}
			else{
                System.out.println("activity=====OTHE ELSE PART========"+activity);			
			}
			
			
			SwingWorker worker = new SwingWorker<String, Object>() {
				@Override
				protected String doInBackground() throws Exception {
					EMAIL_MESSAGE = emailUtil.processAndSendEmail();
					return null;
				}

				@Override
				protected void done() {
						System.out.println("DONE " + EMAIL_MESSAGE);		
				}
			};
			worker.execute();
			System.out.println( "BEFORE RETURNING: " + EMAIL_MESSAGE);
			return EMAIL_MESSAGE;
		}
	
	//SETTER and GETTER METHODS
	public Map<String,String> getInterviewModeMap() {
		return interviewModeMap;
	}

	public void setInterviewModeMap(Map<String,String> interviewModeMap) {
		this.interviewModeMap = interviewModeMap;
	}

	public List<RecruitmentProfile> getRecruitmentProfiles() {
		return recruitmentProfiles;
	}

	public void setRecruitmentProfiles(List<RecruitmentProfile> recruitmentProfiles) {
		this.recruitmentProfiles = recruitmentProfiles;
	}

	public RecruitmentProfileDAO getRecruitmentProfileDAO() {
		return recruitmentProfileDAO;
	}

	public void setRecruitmentProfileDAO(RecruitmentProfileDAO recruitmentProfileDAO) {
		this.recruitmentProfileDAO = recruitmentProfileDAO;
	}


	public String getRrfCode() {
		return rrfCode;
	}


	public void setRrfCode(String rrfCode) {
		this.rrfCode = rrfCode;
	}


	public RecruitmentRequest getRecruitmentRequest() {
		return recruitmentRequest;
	}

	public void setRecruitmentRequest(RecruitmentRequest recruitmentRequest) {
		this.recruitmentRequest = recruitmentRequest;
	}

	public RRFDAO getRrfDAO() {
		return rrfDAO;
	}

	public void setRrfDAO(RRFDAO rrfDAO) {
		this.rrfDAO = rrfDAO;
	}

	public String getActivity() {
		return activity;
	}

	public void setActivity(String activity) {
		this.activity = activity;
	}

	public RecruitmentProfile getRecruitmentProfile() {
		return recruitmentProfile;
	}

	public void setRecruitmentProfile(RecruitmentProfile recruitmentProfile) {
		this.recruitmentProfile = recruitmentProfile;
	}

	public boolean isDisableInterviewer1Date() {
		return disableInterviewer1Date;
	}

	public void setDisableInterviewer1Date(boolean disableInterviewer1Date) {
		this.disableInterviewer1Date = disableInterviewer1Date;
	}

	public boolean isDisableInterviewer2Date() {
		return disableInterviewer2Date;
	}

	public void setDisableInterviewer2Date(boolean disableInterviewer2Date) {
		this.disableInterviewer2Date = disableInterviewer2Date;
	}

	public boolean isDisableRecruiterDate() {
		return disableRecruiterDate;
	}

	public void setDisableRecruiterDate(boolean disableRecruiterDate) {
		this.disableRecruiterDate = disableRecruiterDate;
	}

	public Map<String,String> getReleaseOfferLetterMap() {
		return releaseOfferLetterMap;
	}

	public void setReleaseOfferLetterMap(Map<String,String> releaseOfferLetterMap) {
		this.releaseOfferLetterMap = releaseOfferLetterMap;
	}

	public Map<String, Long> getBandsMap() {
		return bandsMap;
	}

	public void setBandsMap(Map<String, Long> bandsMap) {
		this.bandsMap = bandsMap;
	}

	public List<Band> getBands() {
		return bands;
	}

	public void setBands(List<Band> bands) {
		this.bands = bands;
	}

	public RRFOfferLetterHRInputs getRrfOfferLetterHRInputs() {
		return rrfOfferLetterHRInputs;
	}

	public void setRrfOfferLetterHRInputs(RRFOfferLetterHRInputs rrfOfferLetterHRInputs) {
		this.rrfOfferLetterHRInputs = rrfOfferLetterHRInputs;
	}

	public RRFOfferLetterHRInputsDAO getRrfOfferLetterHRInputsDAO() {
		return rrfOfferLetterHRInputsDAO;
	}

	public void setRrfOfferLetterHRInputsDAO(RRFOfferLetterHRInputsDAO rrfOfferLetterHRInputsDAO) {
		this.rrfOfferLetterHRInputsDAO = rrfOfferLetterHRInputsDAO;
	}

	public boolean isHrInputExists() {
		return hrInputExists;
	}

	public void setHrInputExists(boolean hrInputExists) {
		this.hrInputExists = hrInputExists;
	}

	public StreamedContent getFile() {
		return file;
	}

	public void setFile(StreamedContent file) {
		this.file = file;
	}

	public WAMUtil getWamUtil() {
		return wamUtil;
	}

	public void setWamUtil(WAMUtil wamUtil) {
		this.wamUtil = wamUtil;
	}

	public boolean isRenderBackButton() {
		return renderBackButton;
	}

	public void setRenderBackButton(boolean renderBackButton) {
		this.renderBackButton = renderBackButton;
	}

	public boolean isRenderCloseButton() {
		return renderCloseButton;
	}

	public void setRenderCloseButton(boolean renderCloseButton) {
		this.renderCloseButton = renderCloseButton;
	}
	public RecruitmentProfile getDownloadProfile() {
		return downloadProfile;
	}
	public void setDownloadProfile(RecruitmentProfile downloadProfile) {
		this.downloadProfile = downloadProfile;
	}
	public int getSno() {
		return sno;
	}
	public void setSno(int sno) {
		this.sno = sno;
	}

	public RRFManagerRecommendation getRrfManagerRecommendation() {
		return rrfManagerRecommendation;
	}

	public void setRrfManagerRecommendation(RRFManagerRecommendation rrfManagerRecommendation) {
		this.rrfManagerRecommendation = rrfManagerRecommendation;
	}

	public Map<String, String> getHrsMap() {
		return hrsMap;
	}

	public void setHrsMap(Map<String, String> hrsMap) {
		this.hrsMap = hrsMap;
	}

	public List<Employee> getHrList() {
		return hrList;
	}

	public void setHrList(List<Employee> hrList) {
		this.hrList = hrList;
	}

	public TimeZone getTimeZone() {
		return timeZone;
	}

	public void setTimeZone(TimeZone timeZone) {
		this.timeZone = timeZone;
	}

	public String getRequestDate() {
		return requestDate;
	}

	public void setRequestDate(String requestDate) {
		this.requestDate = requestDate;
	}

	public Date getDateAfterFourMnths() {
		return dateAfterFourMnths;
	}

	public void setDateAfterFourMnths(Date dateAfterFourMnths) {
		this.dateAfterFourMnths = dateAfterFourMnths;
	}


}
